package com.ruoyi.system.controller;

import java.util.List;

import com.ruoyi.system.domain.SysUserRole;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ProBase;
import com.ruoyi.system.service.IProBaseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产品基本信息Controller
 * 
 * @author renfx
 * @date 2021-09-07
 */
@RestController
@RequestMapping("/system/base")
public class ProBaseController extends BaseController
{
    @Autowired
    private IProBaseService proBaseService;

    /**
     * 查询产品基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:base:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProBase proBase)
    {
        startPage();
        List<ProBase> list = proBaseService.selectProBaseList(proBase);
        return getDataTable(list);
    }

    /**
     * 导出产品基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:base:export')")
    @Log(title = "产品基本信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ProBase proBase)
    {
        List<ProBase> list = proBaseService.selectProBaseList(proBase);
        ExcelUtil<ProBase> util = new ExcelUtil<ProBase>(ProBase.class);
        return util.exportExcel(list, "产品基本信息数据");
    }

    /**
     * 获取产品基本信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:base:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(proBaseService.selectProBaseById(id));
    }

    /**
     * 新增产品基本信息
     */
    @PreAuthorize("@ss.hasPermi('system:base:add')")
    @Log(title = "产品基本信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProBase proBase)
    {
        return toAjax(proBaseService.insertProBase(proBase));
    }

    /**
     * 修改产品基本信息
     */
    @PreAuthorize("@ss.hasPermi('system:base:edit')")
    @Log(title = "产品基本信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProBase proBase)
    {
        return toAjax(proBaseService.updateProBase(proBase));
    }

    /**
     * 删除产品基本信息
     */
    @PreAuthorize("@ss.hasPermi('system:base:remove')")
    @Log(title = "产品基本信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(proBaseService.deleteProBaseByIds(ids));
    }

    /**
     * 选择产品
     */
    @PreAuthorize("@ss.hasPermi('system:base:choose')")
    @Log(title = "产品基本信息", businessType = BusinessType.PATCH)
    @PatchMapping("/{id}")
    public AjaxResult choose(@PathVariable Integer id)
    {
        return toAjaxChoose(proBaseService.chooseProBase(id));
    }
}
